package com.ds.components.composite;

import com.ds.components.bars.ElbowBar;

import javax.swing.*;
import java.awt.*;

public abstract class ComponentBar
{
	public ElbowBar topElbowBar;
	public ElbowBar bottomElbowBar;
	public JComponent elbowPanel;
	protected JPanel contents = new JPanel( new BorderLayout() );

	public JComponent getMainContainer()
	{
		if( this.elbowPanel == null )
		{
			throw new NullPointerException( "Composite component, inner parts must be instantiated first." );
		}

		this.contents.removeAll();

		if( this.topElbowBar != null )
		{
			this.contents.add( this.topElbowBar, BorderLayout.NORTH );
		}

		if( this.bottomElbowBar != null )
		{
			this.contents.add( this.bottomElbowBar, BorderLayout.SOUTH );
		}

		switch( this.topElbowBar.getConnectorPosition() )
		{
			case ElbowBar.LEFT_CONNECTOR:
				this.contents.add( this.elbowPanel, BorderLayout.WEST );
				break;
			case ElbowBar.RIGHT_CONNECTOR:
				this.contents.add( this.elbowPanel, BorderLayout.EAST );
				break;
		}

		return this.contents;
	}
}
